
<?php
// 新闻添加
if(!empty($_POST)){

  //调用图片上传函数
  $savePath = '';
  if(!empty($_FILES['file']['name'][0])){
    //重组数组
    foreach($_FILES['file']['name'] as $key => $v){
      $filelist[$key]['name']=$_FILES['file']['name'][$key];
      $filelist[$key]['type']=$_FILES['file']['type'][$key];
      $filelist[$key]['tmp_name']=$_FILES['file']['tmp_name'][$key];
      $filelist[$key]['error']=$_FILES['file']['error'][$key];
      $filelist[$key]['size']=$_FILES['file']['size'][$key];
    }

    foreach ($filelist as $value) {
      $savePath = uploads($value);
    }

  }


  // 获取POST数据
  $_POST['url'] = empty($savePath)?'':$savePath;
  $_POST['send_user'] = $_SESSION['admin']['id'];

  // 调用插入语句（add()）函数
  $_rows = add('news',$_POST);

  if($_rows>0){

    if(!empty($_SERVER['HTTP_X_REQUESTED_WITH'])){
      $json['id'] = mysqli_insert_id($link);
      $json['send_user'] = $_SESSION['admin']['username'];
      $json['time'] = date('Y-m-d H:i:s',time());
      echo !empty($json)?json_encode($json):0;die;

    }
    // $id = mysqli_insert_id($link);
    // // 获取动态页面的数据
    //   $constr = file_get_contents("http://localhost/cms/index.php?c=news&a=details&id=$id");

    // // 把动态页面的数据写到指定的文件夹下生成静态页面
    // file_put_contents("./html/$id.html",$constr);

    echo"<script>alert('提交成功');location.href='index.php?c=news&a=list&admin=1';</script>";die;
  }else{
    echo"<script>alert('提交失败');history.go(-1)</script>";die;
  }

}
// 获取分类id
$id = empty($_GET['id'])?0:$_GET['id'];
 //查询顶级分类
$cate = getSelect('cate',"pid = $id");

//判断是否是ajax请求
if(!empty($_SERVER['HTTP_X_REQUESTED_WITH'])){
  echo json_encode($cate);die;

}

//加载后台公共视图
 include (View_PATH.$admin.'/communal.html');


?>

